﻿@{
    var ProductType = @ViewBag.ProductType;
}
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link href="~/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/Content/style.css" />
    <link rel="stylesheet" href="~/assets/css/ace.min.css" />
    <link rel="stylesheet" href="~/assets/css/font-awesome.min.css" />
    <link href="~/Widget/icheck/icheck.css" rel="stylesheet" type="text/css" />
    <!--[if IE 7]>
      <link rel="stylesheet" href="~/assets/css/font-awesome-ie7.min.css" />
    <![endif]-->
    <!--[if lte IE 8]>
      <link rel="stylesheet" href="~/assets/css/ace-ie.min.css" />
    <![endif]-->
    <script src="~/Scripts/jquery-1.9.1.min.js"></script>
    <script src="~/assets/js/bootstrap.min.js"></script>
    <title>添加产品分类</title>
</head>
<body>
    <div class="type_style">
        <div class="type_title">产品类型信息</div>
        <div class="type_content">
            <div class="Operate_btn">
                <a href="javascript:ovid()" id="AddSonType" class="btn  btn-warning"><i class="icon-edit align-top bigger-125"></i>新增子类型</a>
                <a href="javascript:ovid()" id="ProductTypeHidden" class="btn  btn-success"><i class="icon-ok align-top bigger-125"></i>禁用该类型</a>
                <a href="javascript:ovid()" id="DelProductType"  class="btn  btn-danger"><i class="icon-trash   align-top bigger-125"></i>删除该类型</a>
            </div>
            <form action="" id="form-user-add">
                <input type="hidden" class="input-text" value="@if(@ProductType!=null){@ProductType.ID}" id="ID">
                <input type="hidden" class="input-text" value="@if(@ProductType!=null){@ProductType.ParentID}" id="ParentID">
                <div class="Operate_cont clearfix">
                    <label class="form-label"><span class="c-red">*</span>分类名称：</label>
                    <div class="formControls ">
                        <input type="text" class="input-text" value="@if(@ProductType!=null){@ProductType.ProductName}" placeholder="" id="ProductName" name="product-category-name">
                    </div>
                </div>
                <div class="Operate_cont clearfix">
                    <label class="form-label"><span class="c-red">*</span>排序：</label>
                    <div class="formControls ">
                        <input type="text" class="input-text" value="@if(@ProductType!=null){@ProductType.Sort}" placeholder="" id="Sort" name="product-category-name">
                    </div>
                </div>
                <div class="Operate_cont clearfix">
                    <label class="form-label">备注：</label>
                    <div class="formControls">
                        <textarea name="" id="Context" rows="" class="textarea" placeholder="说点什么...最少输入10个字符" datatype="*10-100" dragonfly="true" nullmsg="备注不能为空！" onKeyUp="textarealength(this,100)">@if(@ProductType!=null){@ProductType.Context}</textarea>
                        <p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
                    </div>
                </div>
                <div class="">
                    <div class="" style=" text-align:center">
                        <input class="btn btn-primary radius" id="AddProductType" type="button" value="提交">
                    </div>
                </div>
            </form>
        </div>
    </div>
    <script type="text/javascript" src="~/Widget/icheck/jquery.icheck.min.js"></script>
    <script type="text/javascript" src="~/Widget/Validform/5.3.2/Validform.min.js"></script>
    <script type="text/javascript" src="~/assets/layer/layer.js"></script>
    <script type="text/javascript" src="~/Scripts/H-ui.js"></script>
    <script type="text/javascript" src="~/Scripts/H-ui.admin.js"></script>
    <script type="text/javascript">
        $(function () {
            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'

            });

            $("#form-user-add").Validform({
                tiptype: 2,
                callback: function (form) {
                    form[0].submit();
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.$('.btn-refresh').click();
                    parent.layer.close(index);
                }
            });
            //添加
            $("#AddProductType").click(function () {
                var ProductType = {};
                ProductType.ID = $("#ID").val();
                ProductType.ProductName = $("#ProductName").val();
                ProductType.Sort = $("#Sort").val();
                ProductType.Context = $("#Context").val();
                ProductType.ParentID = $("#ParentID").val();
                if (ProductType.ID == null||ProductType.ID=="") {
                    $.ajax({
                        url: "/ProductType/AddParendType",
                        data: ProductType,
                        type: "post",
                        success: function (result) {
                            if (result.Success) {
                                alert(result.Context);
                                location.reload();//刷新页面
                            }
                            else {
                                alert("失败！");
                            }
                        }
                    })
                } else {
                     $.ajax({
                        url: "/ProductType/UpdateParendType",
                        data: ProductType,
                        type: "post",
                        success: function (result) {
                            if (result.Success) {
                                alert("修改成功！");
                                location.reload();//刷新页面
                            }
                            else {
                                alert("修改失败！");
                            }
                        }
                    })
                }
            })
            //点击新增子类型时 将父级ID赋值给主键ID 再将主键ID清空
            $("#AddSonType").click(function () {
                var ID = $("#ID").val();
                var ParentID = $("#ParentID").val();
                if (ParentID != 1) {
                    layer.alert('不能添加第三级子菜单', {
                        title: '提示框',
                        icon: 1,
                    });
                    return;
                }
                //将父级ID赋值给主键ID 依靠父级ID是否有值在方法里判断是添加父菜单还是字菜单
                $("#ParentID").val(ID);
                //将主键ID清空
                $("#ID").val("");
            })
            //禁用该类型
            $("#ProductTypeHidden").click(function () {
                var ID = $("#ID").val();
                 $.ajax({
                        url: "/ProductType/HiddenParendType?ID="+ID,
                        type: "post",
                        success: function (result) {
                            if (result.Success) {
                                alert("禁用成功！");
                                location.reload();//刷新页面
                            }
                            else {
                                alert("禁用失败！");
                            }
                        }
                    })
            })
             //删除该类型
            $("#DelProductType").click(function () {
                var ID = $("#ID").val();
                 $.ajax({
                        url: "/ProductType/DelParendType?ID="+ID,
                        type: "post",
                        success: function (result) {
                            if (result.Success) {
                                alert("删除成功！");
                                location.reload();//刷新页面
                            }
                            else {
                                alert("删除失败！");
                            }
                        }
                    })
            })
        });
    </script>
</body>
</html>